
var IndexView = View.extend(IndexView = {
    
    init: function() {
        var self = this;
        
        $(".join-link").click(function(e) {
            e.preventDefault();
            
            var link = $(this);
            
            if( link.hasClass("joined") ) {
                return;
            }
            
            self.joinOrganisation(link, function() {
                link.html("Joined").removeClass("btn-success").addClass("btn-default joined");
            });
        });
    },
    
    joinOrganisation: function($link, callback) {
        var url = $link.attr('href');

        $.post(url, function() {
            if( callback && $.isFunction(callback) ) {
                callback();
            }
        });
    }
});

$(document).ready(function() {
    var index = new IndexView();
    index.init();
});
